<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>客户信息</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../layui-v2.6.8/layui/css/layui.css">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>修改个人信息</legend>
</fieldset>
<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">编号</label>
    <div class="layui-input-inline">
      <input type="text" id="cid" required lay-verify="required" placeholder="请输入编号" autocomplete="off" class="layui-input">
<!--      <button type="button" id="select"  class="layui-btn layui-btn-normal">查询</button>-->
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">联系方式</label>
    <div class="layui-input-inline">
      <input type="text" id="cphone" required lay-verify="required" placeholder="请输入修改后的联系方式" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" onclick="update()">修改</button>
    </div>
  </div>
  <table class="layui-hide" id="customer" lay-filter="operation"></table>
</form>
<script src="../../layui-v2.6.8/layui/layui.js"></script>
<script>
  var table = layui.table;
  layui.use(['table'],function () {
    table.render({
      elem: '#customer',
      url: 'http://localhost:8080/byCid?cid='+cid,
      cols: [[
        {type: 'checkbox', fixed: 'left'}
        , {field: 'cid', title: '客户编号', sort: true}
        , {field: 'cname', title: '客户姓名'}
        , {field: 'cphone', title: '客户联系方式'}
        , {field: 'user_name', title: '账号'}
        , {field: 'password', title: '密码'}
      ]],

    });
  })
  var layer = layui.layer;
  var $=layui.$;
  var table=layui.table;
  var cid = sessionStorage.getItem("cid");
  $('#select').click(function (){
    // var cid=$('#cid').val()
    if(cid==null||cid==undefined||cid==""){
      alert("请输入修改后的联系方式");
    }else {
      layer.open({
        area: ['100%', '400px'],
        title:["查询结果","align:center"],
        maxmin:false,
        content : '<div><table id="a"></table></div>',
        success:function (){
          table.render({
            elem:'#a',
            url:'http://localhost:8080/byCid?cid='+cid,
            page:false,
            cols:[[
              {field:'cid',title: '客户编号',sort:true}
              ,{field: 'cname',title: '客户名称'}
              ,{field: 'cphone',title: '客户联系方式'}
              ,{field: 'user_name',title: '账号'}
              ,{field: 'password',title: '密码'}
            ]]
          })
        }
      })
    }
  })


  function update() {
    var $ =layui.$;
    var cid = $("#cid").val();
    var cphone = $("#cphone").val();


    var data={

      "cid":cid,
      "cphone":cphone,


    }
    var layer = layui.layer;
    var url ="http://localhost:8080/updateCus";
    $.ajax({
      url:url,
      type:"get",
      dataType:"json",
      async:true,
      // cache:false,
      data:data,
      success: function(data){
        console.log(data)
        if (data.code == 0) {

          layer.msg("修改成功", {icon: 6,time:1800},function (){
            // location.href = '../car/addCar.html';
          });
          // window.location.href = 'CustomerIndex.html';
        } else {
          layer.msg("修改失败", {icon: 5});
        }
        return false;
      }
    });
  }
</script>